package problems.practice;

import java.util.Arrays;

/**
 * 1684. 统计一致字符串的数目
 * <p>https://leetcode.cn/problems/count-the-number-of-consistent-strings/</p>
 *
 * @author habitplus
 * @since 9:19, 2022/10/3
 */
public class T1684 {
    public int countConsistentStrings(String allowed, String[] words) {
        boolean[] map = new boolean[26];

        for (char c : allowed.toCharArray()) {
            map[c - 'a'] = true;
        }

        int ret = 0;

        for (String w : words) {
            if (check(map, w)) ++ret;
        }

        return ret;
    }

    private boolean check(boolean[] map, String s) {
        for (char c : s.toCharArray()) {
            if (!map[c - 'a']) return false;
        }
        return true;
    }
}
